import React from 'react';
import { observer, inject } from 'mobx-react';
import { loadFullResource } from '../../util/asyncLoad';

@inject('globalStore')
@observer
export default class Main extends React.Component{
    constructor(){
        super();
    }
    componentWillMount(){
        window.JS_LOAD_DURATION = window.JS_LOAD_END - window.JS_LOAD_START;    //html静态资源耗时
        window.Route_DURATION = new Date().getTime() - window.JS_LOAD_END;      //中转耗时(路由跳转耗时、多语言加载耗时等)
        //发送loadForm异步接口
        const { location,globalStore } = this.props;
        const urlParams = location.query || {};
        globalStore.loadBaseInfo(urlParams);
        //Chrome下优先加载全量组件库
        var calLoadTime = urlParams.calLoadTime || "1";
        if(globalStore.browserVersion === "Chrome" || (globalStore.browserVersion !== "Chrome" &&  calLoadTime !== "1"))
            loadFullResource();
    }
    render(){
        const location = this.props.location || {};
        const isPrint = location.query && location.query.isprint == "1";
        const isPreView = location.query && location.query.isPreView == "1";
        let Comp = null;
        if(isPreView)
            Comp = require("./PreView").default;
        else if(isPrint)
            Comp = require("./ReqIndex4Print").default;
        else
            Comp = require("./ReqIndex").default;
        return (<Comp ecId={`${this && this.props && this.props.ecId || ''}_Comp@upn4fo`} location={this.props.location} />);
    }
}